package com.bilibili.bilibili.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.android.volley.VolleyError;
import com.bilibili.bilibili.R;
import com.bilibili.bilibili.adapter.EveryoneSeekPagerAdapter;
import com.bilibili.bilibili.bean.EveryoneSeekBean;
import com.bilibili.bilibili.customview.NoScrollViewPager;
import com.bilibili.bilibili.fragment.DramaFragment;
import com.bilibili.bilibili.fragment.MoviesFragment;
import com.bilibili.bilibili.fragment.UPMainFragment;
import com.bilibili.bilibili.network.HttpGetData;
import com.bilibili.bilibili.network.VolleyInterface;
import com.bilibili.bilibili.utils.GsonUtil;
import com.flyco.tablayout.SlidingTabLayout;
import com.google.gson.reflect.TypeToken;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class EveryoneSeek extends AppCompatActivity {
    private static final String TAG ="EveryoneSeek" ;
    private NoScrollViewPager mViewpager;
    private List<Fragment> mFragments;
    private SlidingTabLayout mTablayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_everyone_seek);
        mTablayout = (SlidingTabLayout) findViewById(R.id.everyone_seek_tablayout);
        mViewpager = (NoScrollViewPager) findViewById(R.id.everyone_seek_viewpager);
        initDabase();
        initView();

    }

    private void initView() {




    }
    private void initDabase() {

        String path="http://app.bilibili.com/x/v2/search?duration=0&keyword=%E4%BA%BA%E6%B8%A3%E7%9A%84%E6%9C%AC%E6%84%BF&pn=1&ps=20&appkey=1d8b6e7d45233436&build=500001&mobi_app=android&platform=android";
        HttpGetData.RequestGet(this, path, "everyone", new VolleyInterface(this,VolleyInterface.mListener,VolleyInterface.mErrorListener) {
            @Override
            public void onMySuccess(String result) {
                EveryoneSeekBean everyoneSeekBean= GsonUtil.parseJsonToObj(result, new TypeToken<EveryoneSeekBean>() {
                });
                EveryoneSeekBean.DataBean data = everyoneSeekBean.getData();
                List<EveryoneSeekBean.DataBean.NavBean> nav = data.getNav();

                List<EveryoneSeekBean.DataBean.ItemsBean.ArchiveBean> archive = data.getItems().getArchive();
                /*ArrayList arrayList=new ArrayList();
                arrayList.add(archive);*/
                mFragments = new ArrayList<>();
                Bundle bundle=new Bundle();
                bundle.putSerializable("ARC", (Serializable) archive);

                DramaFragment dramaFragment=new DramaFragment();
                dramaFragment.setArguments(bundle);
                UPMainFragment upMainFragment=new UPMainFragment();
                MoviesFragment moviesFragment=new MoviesFragment();
                mFragments.add(dramaFragment);
                mFragments.add(upMainFragment);
                mFragments.add(moviesFragment);
                EveryoneSeekPagerAdapter everyoneSeekAdapter=new EveryoneSeekPagerAdapter(getSupportFragmentManager(), mFragments);
                mViewpager.setOffscreenPageLimit(3);
                mViewpager.setAdapter(everyoneSeekAdapter);
                mTablayout.setViewPager(mViewpager);
                mViewpager.setCurrentItem(0);

            }

            @Override
            public void onMyError(VolleyError error) {
                Log.d(TAG, "onMyError: ");

            }
        });


    }
}
